﻿using DataProcess.Authable;
using System;
using System.IO;
using static System.Console;
namespace BlackBoxForAdmin
{
    class Program
    {
        static string initcode = "832c65df";
        public static string MoreTimeStr(int t, DateTime date)
        {
            DataProcess.Encryption.Encryption encryption = new DataProcess.Encryption.Encryption();
            DateTime d = DateTime.Now;
            string code = genInitCode(d.Ticks);
            using (FileStream fs = new FileStream("data.txt", FileMode.OpenOrCreate))
            {
                
                using (StreamWriter writer = new StreamWriter(fs))
                {
                    writer.WriteLine(code);
                }
            }
            WriteLine("下一个ID:" + code);
                return encryption.AdvancedEncrypt($"LoveU,{t},{date.Year},{date.Month},{date.Day},{d.Ticks}", initcode, System.Text.Encoding.UTF8) + "|" + d.Ticks;
        }
        public static string ReadForResult(string code)
        {
            DataProcess.Encryption.Encryption encryption = new DataProcess.Encryption.Encryption();
            return encryption.AdvancedDecrypt(code, initcode, System.Text.Encoding.UTF8);
        }
        public static string genInitCode(long tick)
        {
            DataProcess.Authable.HMACbasedOneTimeAuthenticator authenticator = new HMACbasedOneTimeAuthenticator() { Digit = 8 };
            authenticator.OnResult += Authenticator_OnResult;
            authenticator.Key = "TbsAndRyq";
            authenticator.CodingLevel = DataProcess.Encryption.HMACMaker.Level.SHA256;
            string code = authenticator.Generate(tick);
            return code;
        }
        private static string Authenticator_OnResult(byte[] rawdata, string nowcode)
        {
            string result = "";
            for (int i = 17; i < 21; i++)
            {
                result += DataProcess.Mathematics.NumberCase.ExchangeFromTen(rawdata[i], 16, 2);
            }
            return result;
        }
        static void Main(string[] args)
        {
            WriteLine(ReadForResult("BB8XHwMsHFQWIR05BjIwMjEvBS8AIDIwAjAwOjECHjEOGiZaDQYyGREdHFULEFYgBRcrHwMsJ1YR 43C232C1204130F1010D10E121342143123C41341C432C32C12B"));
        }
    }
}
